package com.info.zhiduoduo.repository.mapper.notice;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.notice.NoticeDto;
import com.info.zhiduoduo.repository.entity.notice.Notice;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 系统公告
 */
public interface NoticeMapper extends BaseMapper<Notice> {

	@Select(" select n.*,sm.managername from zdd_notice n " +
			" join zdd_system_manager sm on sm.managerid=n.managerid " +
			" where n.title like '%${title}%' " +
			" and n.type in(${type}) " +
			" and n.createtime between #{startDate} and #{endDate} " +
			" and (n.specify_id is null or n.specify_id = #{userid})" +
			" order by n.id DESC ")
	List<NoticeDto> getListByTypes(@Param("title") String title, @Param("type") String type, @Param("startDate") Date startDate, @Param("endDate") Date endDate,Integer userid);


	// 企业pc端查看 公告
	@Select(" select n.*,sm.managername,0 as isRead from zdd_notice n " +
			" join zdd_system_manager sm on sm.managerid=n.managerid " +
			" and n.type in(${type}) " +
			" order by n.id DESC ")
	List<NoticeDto> queryListByTypes(@Param("type") String type);


	@Select(" select n.*,sm.managername from zdd_notice n " +
			" join zdd_system_manager sm on sm.managerid=n.managerid " +
			" where n.title like '%${title}%' " +
			" and IF(#{type}=0,1=1,n.type=#{type})" +
			" and n.createtime between #{startDate} and #{endDate} " +
			" order by n.id DESC ")
	List<NoticeDto> getList(@Param("title") String title, @Param("type") int type, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

	@Select(" select n.*,sm.managername from zdd_notice n " +
			" join zdd_system_manager sm on sm.managerid=n.managerid " +
			" where n.id=#{id}")
	NoticeDto getDetail(@Param("id") Integer id);
}
